home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gui / muibuilderv11.lha / muibuilder / mb / e / Application+Locale.e < prev    next >
Text File  |  1994-03-15  |  5KB  |  146 lines

  1. /******************************************************************************
  2.     Here is an example of an "environnement file". All you have to do, si to
  3. fill it with :
  4.     - some constant declarations and array initialisations for localisation
  5.     - use MUIBuilder+GenCodeE to generate the create_app() function
  6.     - add the code for your application !!!
  7. ******************************************************************************/
  8.  
  9. OPT OSVERSION=37
  10.  
  11.     /* Module definitions */
  12. MODULE 'muimaster', 'libraries/mui'
  13. MODULE 'utility/tagitem', 'utility/hooks'
  14. MODULE 'intuition/classes', 'intuition/classusr'
  15. MODULE 'locale', 'libraries/locale'
  16.  
  17.     /* Error handling */
  18. ENUM NO_LIBRARY, MUI_APPLICATION_FAILURE
  19. RAISE   NO_LIBRARY              IF OpenLibrary()=NIL,
  20.         MUI_APPLICATION_FAILURE IF Mui_NewObjectA()=NIL
  21.  
  22.     /* Object definitions */
  23. OBJECT fc_type
  24.     id  :LONG
  25.     str :LONG
  26. ENDOBJECT
  27.  
  28.     /* Constant definitions */
  29. CONST MUI_TRUE = 1
  30.         /******************************************
  31.             Add here some constant declarations
  32.             for localisation.
  33.         ******************************************/
  34.  
  35.     /* Global variables */
  36. DEF catalog_application:PTR TO catalog
  37. DEF array_application[]:ARRAY OF fc_type        /* Update array size */
  38. /*MUIB*/
  39.  
  40.  
  41.     /* Main procedure */
  42. PROC main() HANDLE
  43.     DEF signal, result_DoMethod, running = TRUE
  44.  
  45.     localebase := OpenLibrary('locale.library', 0)
  46.     muimasterbase := OpenLibrary('muimaster.library', 0)
  47.     open_application_catalog(NIL, NIL)
  48.     create_app()
  49.  
  50.     WHILE running
  51.         result_DoMethod := doMethod( app, [ MUIM_Application_Input, {signal} ] )
  52.         SELECT result_DoMethod
  53.             CASE MUIV_Application_ReturnID_Quit
  54.                 running := FALSE
  55.         ENDSELECT
  56.         IF (running AND signal) THEN Wait( signal )
  57.     ENDWHILE
  58.  
  59.     Mui_DisposeObject( app )
  60.     close_application_catalog()
  61.     CloseLibrary( muimasterbase )
  62.     CloseLibrary( localebase )
  63.  
  64. EXCEPT
  65.     SELECT exception
  66.         CASE NO_LIBRARY
  67.         CASE MUI_APPLICATION_FAILURE
  68.     ENDSELECT
  69. ENDPROC
  70.  
  71.  
  72.     /* Procedure generated by GenCodeE which creates your application */
  73. PROC create_app()
  74. ENDPROC
  75.  
  76.  
  77.     /* DoMethod() function */
  78. PROC doMethod( obj:PTR TO object, msg:PTR TO msg )
  79.  
  80.     DEF h:PTR TO hook, o:PTR TO object, dispatcher
  81.  
  82.     IF obj
  83.         o := obj-SIZEOF object     /* instance data is to negative offset */
  84.         h := o.class
  85.         dispatcher := h.entry      /* get dispatcher from hook in iclass */
  86.         MOVEA.L h,A0
  87.         MOVEA.L msg,A1
  88.         MOVEA.L obj,A2           /* probably should use CallHookPkt, but the */
  89.         MOVEA.L dispatcher,A3    /*   original code (DoMethodA()) doesn't. */
  90.         JSR (A3)                 /* call classDispatcher() */
  91.         MOVE.L D0,o
  92.         RETURN o
  93.     ENDIF
  94.  
  95. ENDPROC NIL
  96.  
  97.  
  98.     /* Extended KeyButton for localized buttons */
  99. PROC et_key_button( text:PTR TO CHAR ) RETURN KeyButton( (text+3), text[1] )
  100.  
  101.  
  102.     /* An easy OpenCatalog() function */
  103. PROC open_application_catalog(loc:PTR TO locale, language:PTR TO CHAR)
  104.     DEF tag, tagarg, dummy_var = 0
  105.  
  106.         /******************************************
  107.             Add here some array initialisations
  108.             for localisation.
  109.         ******************************************/
  110.  
  111.     IF (localebase AND (catalog_application = NIL))
  112.         IF language
  113.             tag := OC_LANGUAGE
  114.             tagarg := language
  115.         ELSE
  116.             tag:= TAG_IGNORE
  117.         ENDIF
  118.  
  119.         catalog_application := OpenCatalogA(loc, 'application.catalog',
  120.                                             [   OC_BUILTINLANGUAGE, 'english',  /* Update built-in language */
  121.                                                 tag, tagarg,
  122.                                                 OC_VERSION, 0,                  /* Update catalog version number */
  123.                                                 TAG_DONE    ])
  124.     ENDIF
  125. ENDPROC
  126.     
  127.                                 
  128.     /* An easy CloseCatalog() function  */
  129. PROC close_application_catalog()
  130.  
  131.     IF localebase THEN CloseCatalog( catalog_application )
  132.     catalog_application := NIL
  133. ENDPROC
  134.  
  135.  
  136.     /* A GetString() function for localized strings */
  137. PROC get_application_string( strnum )
  138.     DEF defaultstr:PTR TO CHAR, i = 0
  139.  
  140.         /* Fill the 2 (i < ?) tests by the array size */
  141.     WHILE ((i < ?) AND (array_application[i].id <> strnum)) DO INC i
  142.     defaultstr := IF (i < ?) THEN array_application[i].str ELSE NIL
  143.  
  144. ENDPROC IF catalog_application THEN GetCatalogStr( catalog_application, strnum, defaultstr ) ELSE defaultstr
  145.  
  146.